//
//  LKNetworkTool.swift
//  新浪微博
//
//  Created by 胡不归是大虾 on 16/9/24.
//  Copyright © 2016年 胡不归是大虾. All rights reserved.
//

import UIKit
import AFNetworking
enum HTTPMethod {
    case Get
    case Post
}
class LKNetworkTool: AFHTTPSessionManager {
    //声明单例对象
    static let sharedTool : LKNetworkTool = {
        let tool = LKNetworkTool()
        tool.responseSerializer.acceptableContentTypes?.insert("text/plain")
        return tool
    }()
    func request(method:HTTPMethod,urlString:String,parameters:Any?,finishedClosure:@escaping (Any?,Error?)->()) {
        let successClosure = { (dataTask:URLSessionDataTask,responseObject:Any?)->() in
            finishedClosure(responseObject,nil)
        }
        let failureClosure = {(dataTask:URLSessionDataTask?,error:Error)->() in
            finishedClosure(nil,error)
        }

        if method == .Get {
            get(urlString, parameters: parameters, progress: nil, success: successClosure, failure: failureClosure)
        }
        else
        {
            post(urlString, parameters: parameters, progress: nil, success: successClosure, failure: failureClosure)
        }
    }
}
